package com.bonc.insight.controller;

import com.bonc.insight.entity.TOauth2User;
import com.bonc.insight.service.impl.TOauth2UserServiceImpl;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bonc.vo.ResultVo;
import java.util.List;

/**
 * <p>
 *   前端控制器
 * </p>
 *
 * @author bonc
 * @since 2022-01-14
 */
@RestController
@RequestMapping("/insight/toauth2user")
public class TOauth2UserController {

   @Resource
   private TOauth2UserServiceImpl toauth2userService;

    /**
      * 单条保存or更新
      * @param toauth2user
      * @return
      */
    @PostMapping("/saveOrUpdate")
    public ResultVo saveOrUpdate(@RequestBody TOauth2User toauth2user){
        boolean state = toauth2userService.saveOrUpdate(toauth2user);
        if(!state){
            return ResultVo.getFail();
        }
        return ResultVo.getSuccess();
    }

    /**
     * 批量保存or批量更新
     * @param toauth2userList
     * @param batchSize
     * @return
     */
    @PostMapping("/saveOrUpdateBatch")
    public ResultVo saveOrUpdateBatch(@RequestParam("toauth2userList") List< TOauth2User> toauth2userList,int batchSize){
        boolean state = toauth2userService.saveOrUpdateBatch(toauth2userList,batchSize);
        if(!state){
            return ResultVo.getFail();
        }
        return ResultVo.getSuccess();
    }

    /**
    * 通过id删除
    * @param id
    * @return
    */
    @PostMapping("/removeById")
    public ResultVo removeById(@RequestParam("id") String id) {
        boolean state = toauth2userService.removeById(id);
        if(!state){
            return ResultVo.getFail();
        }
        return ResultVo.getSuccess();
    }

    /**
    * 通过id集合删除
    * @param ids
    * @return
    */
    @PostMapping("/removeByIds")
    public ResultVo removeByIds(@RequestParam("ids") List<String> ids) {
        boolean state = toauth2userService.removeByIds(ids);
        if(!state){
            return ResultVo.getFail();
        }
        return ResultVo.getSuccess();
    }

    /**
     * 通过id查询
     * @param id
     * @return
     */
    @PostMapping("/getById")
    public ResultVo<TOauth2User> getById(@RequestParam("id") String id) {
        return ResultVo.getSuccess(toauth2userService.getById(id));
    }

    /**
     * 分页条件查询
     * @param toauth2user
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public ResultVo<IPage<TOauth2User>> getPageList(@RequestBody TOauth2User toauth2user,
                                                        @RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                                        @RequestParam(value = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
        return ResultVo.getSuccess(toauth2userService.getTOauth2UserList(pageNum,pageSize,toauth2user));
    }

}
